package com.atguigu.juc02;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


class MyThread implements Callable<Integer>
{
    @Override
    public Integer call() throws Exception
    {
        System.out.println("------come in");
        return 1024;
    }
}


/**
 * @auther zzyy
 * @create 2020-03-28 16:30
 * java里面，第三种获得多线程的方式
 * 一个新的接口，Callable
 */
public class CallableDemo
{
    public static void main(String[] args) throws ExecutionException, InterruptedException
    {
        //Thread(Runnable target, String name) Allocates a new Thread object.

        //FutureTask(Callable<V> callable) Creates a FutureTask that will, upon running, execute the given Callable.

        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread());

        Thread thread = new Thread(futureTask,"A");
        thread.start();

        System.out.println(futureTask.get());//这个一般放在最后。
    }
}